I'm writing a code where it draws a number of long strings (texts) onto a canvas (dialog box) but the string is too long and I need a way to shorten it so it can fit the page. Preferably I want to put it into a text box. |
Re: Concatenate a Long String into a Smaller Text Pox on Canvas |
Re: Concatenate a Long String into a Smaller Text Pox on Canvas
Some years ago I implemented a simple, editable, scrollable spreadsheet on a canvas, where I did something like that. What I did was to iterate over the string and then use the 'width(Canvas, string)' and 'height(Canvas, string)' functions to get the part of the string that will fit into the canvas width. I did something like this (cannot find the full code):
DB artBox = create "Try resizing this window"
string s = "The quick brown fox jumps over the lazy brown dog!"
int marginx = 5
int linespace = 5
void renderString (DBE c, string s, int startPos, int posx, int posy, int maxx, int maxy) {
int posToFit = startPos
int iLen = length s
int h = height(c,s)
if (posy > maxy) return
int w = maxx-posx
while (width (c, s[startPos:posToFit +1]) < w && posToFit < iLen) posToFit++
draw(c, posx, h+posy, s[startPos:posToFit ])
if (posToFit< iLen-1) renderString(c,s,posToFit+1,posx,posy+h+linespace,maxx,maxy)
int lastPos
}
void doDrawing(DBE art){
// repaint callback function
int cw = width art
int ch = width art
renderString (art, s,0, 10,10, cw-20, ch-20)
}
DBE art = canvas(artBox, 200, 300, doDrawing)
show artBox
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Concatenate a Long String into a Smaller Text Pox on Canvas -Louie |
Re: Concatenate a Long String into a Smaller Text Pox on Canvas Is there a way to access the dxl code for the "graphics mode on or off"? or what do you guys think would be the best way to create this "tree diagram" in terms of if the string i'm painting onto the canvas is too long, how do i wrap the text heres a picture of what i have so far and you can see why it's a problem. the text, if too long, overlaps w/ the next. i haven't drawn the lines to connect the links yet. thanks guys! Attachments attachment_14777901_Untitled.jpg |
Re: Concatenate a Long String into a Smaller Text Pox on Canvas phan423 - Thu Jan 12 20:33:11 EST 2012 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |